$(function(){
    /*基于准备好的dom,初始化echarts实例*/
	/*
	 * 默认隐藏的话，初始化之前需要盒子给定宽度*/
	/*var w = $("#showEcharts").parent().width();
	$("#showEcharts").css("width",(w*0.98)+"px");*/
    var myChart = echarts.init(document.getElementById('showEcharts'));
    var data=JSON.parse(alldata);
    if(data.length<1){
    	showEcharts();
    	return;
    }
    var bman=new Array();
    var lman=new Array();
    var sman=new Array();
    var bwoman=new Array();
    var lwoman=new Array();
    var swoman=new Array();
    var name=new Array();
    var man=new Array();
    var woman=new Array();
    var child=new Array();
    for(var i in data){
    	name.push(data[i].name);
    	man.push(data[i].man);
    	woman.push(data[i].woman);
    	child.push(data[i].man+data[i].woman);
    	bman.push(data[i].bman);
    	lman.push(data[i].lman);
    	sman.push(data[i].sman);
    	bwoman.push(data[i].bwoman);
    	lwoman.push(data[i].lwoman);
    	swoman.push(data[i].swoman);
    }
    /*指定图标配置项数据*/
    option = {
    tooltip : {
        trigger: 'axis',
        axisPointer : {             /*坐标轴指示器，坐标轴触发有效*/
            type : 'shadow'        /*默认为直线，可选为：'line' | 'shadow'*/
        }
    },
    legend: {
        data:['本地儿童男','本地儿童女','流动儿童男','流动儿童女','临时儿童男','临时儿童女','所有儿童']
    },
    grid: {
        left: '3%',
        right: '4%',
        bottom: '3%',
        containLabel: true
    },
    xAxis : [
        {
            type : 'category',
            boundaryGap : true,
            data :name
        }
    ],
    yAxis : [
        {
            type : 'value'
        }
    ],
    series : [
        {
            name:'本地儿童男',
            type:'bar',
            stack: '本地儿童',
            barWidth : 20,
            data:bman
        },
        {
            name:'本地儿童女',
            type:'bar',
            stack: '本地儿童',
            data:bwoman
        },
        {
            name:'流动儿童男',
            type:'bar',
            stack: '流动儿童',
            barWidth : 20,
            data:lman
        },
        {
            name:'流动儿童女',
            type:'bar',
            stack: '流动儿童',
            data:lwoman
        },
        {
            name:'临时儿童男',
            type:'bar',
            stack: '临时儿童',
            barWidth : 20,
            data:man
        },
        {
            name:'临时儿童女',
            type:'bar',
            stack: '临时儿童',
            data:swoman
        },
        {
            name:'所有儿童',
            type:'bar',
            barWidth : 30,
            data:child
        }
    ]
};

	/* 使用刚刚指定的配置项和数据显示图表*/
	myChart.setOption(option);
	/*容器大小自适应*/
	window.onresize =  myChart.resize;
});
